package com.tan.lbs;

import com.tan.lbs.dao.GameDAO;
import com.tan.lbs.dao.NPCDAO;
import com.tan.lbs.dao.impl.GameDAOImpl;
import com.tan.lbs.dao.impl.NPCDAOImpl;
import com.tan.lbs.entity.NPC;
import com.tan.lbs.util.Constants;
import com.tan.lbs.util.SQLiteDatabaseHelper;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class NPCGreetingActivity extends Activity{
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.npcgreeting);

		
		Intent intent = getIntent();
		String name = intent.getStringExtra("name");
		String greet = intent.getStringExtra("greet");
		final String npcID = intent.getStringExtra("npcID");
		String iconID = intent.getStringExtra("iconID");
		final String startDialogNodeID = intent.getStringExtra("startDialogNodeID");
			GameDAO gameDAO = new GameDAOImpl(this);
			getSharedPreferences(Constants.PREFS_NAME, 0).getString("currentGameID", "");
		
		((TextView)findViewById(R.id.npcGreeting)).setText(greet);
		((TextView)findViewById(R.id.npcnameInGreeting)).setText(name);
		((Button)findViewById(R.id.talkmoreBtn)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				NPCDAO npcDAO = new NPCDAOImpl(NPCGreetingActivity.this);
				String status = npcDAO.readNPCStatus(npcID);
				
				if(status.equals(NPC.NOT_CHATTABLE)) {
					Toast.makeText(NPCGreetingActivity.this, "You cannot talk with this NPC. It seems you have to unlock something.", Toast.LENGTH_LONG).show();
				} else {
					if(status.equals(NPC.END_CHAT)) {
						Toast.makeText(NPCGreetingActivity.this, "You've finished a chat to uncover something. Go on to find something else.", Toast.LENGTH_LONG).show();
					}
					Intent intent = new Intent();
					intent.putExtra("npcID",npcID);
					intent.putExtra("startDialogNodeID",startDialogNodeID);
					intent.setClass(NPCGreetingActivity.this, NPCTalkingActivity.class);
					NPCGreetingActivity.this.startActivity(intent);
				}
			}
			
		});
		
		((Button)findViewById(R.id.backToMapBtn)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
			
		});
	}
}
